﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Configuration
{
    public static class ConfigurationBuilderExtensions
    {
        public static IConfigurationBuilder AddEncryptedJsonFile(
            this IConfigurationBuilder builder,
            string path,
            string encryptionKey = null,
            bool optional = false,
            bool reloadOnChange = false)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("File path must not be null or empty", nameof(path));
            }

            var source = new EncryptedConfigurationSource(path, encryptionKey);

            // 添加到配置构建器
            return builder.Add(source);
        }
    }
}
